class Animal {
    public String name;
    public int age;

    public void eat() {
        System.out.println(name + " is eat");
    }
    public void sleep() {
        System.out.println(name + " is sleep");
    }
}

// extends 继承的关键字
class Dog extends Animal{
    public int a;
}


// -----------------------------------

// 派生类中存在与父类中名字一样的同名变量
class Base {
    public int a = 10;
    public int b = 11;

    public void print() {
        System.out.println("Base");
    }
}

class Derived extends Base {
    public int a = 100;
    public char b = 'b';

    public void setMember() {
        a = 1;
        b = 'c';
    }

    public void print() {
        super.print();
        System.out.println("Derived");
    }

    public void show() {
        System.out.println(a);
        System.out.println(b);
        System.out.println(super.a);      // 同名时，访问父类中的，类似 python 的; super可以暂且理解为父类对象的引用
    }
}

// ----------------------------------
// 父类有构造函数
class Base1 {
    public int a;

    public Base1(int a) {
        this.a = a;
    }
}

class Derived1 extends Base1 {
    int b;
    public Derived1(int _a, int _b) {
        super(_a);        // 首先要用super构造父类， 这点与 python 一样
        b = _b;
    }
}


public class Class6_Inherit {
    public static void main(String[] args) {
        Derived1 d = new Derived1(1, 2);
    }

    public static void main2(String[] args) {
        Derived d = new Derived();
        d.show();
        d.print(); //  就近，调派生类自己的
    }

    public static void main1(String[] args) {
        Dog dog = new Dog();
        dog.name = "dog";
        dog.eat();
    }
}
